package cn.marinda.resturants.controller;

import cn.marinda.resturants.entity.Salarys;
import cn.marinda.resturants.global.Pages;
import cn.marinda.resturants.service.SalaryService;
import cn.marinda.resturants.utils.ApiResult;
import cn.marinda.resturants.utils.PagesResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;

/** 工资控制器
 *
 * @author Marinda
 * @date 2021/12/2
 * @version 1.0
 *
 */
@RestController
@RequestMapping("/salarys")
public class SalarysController {

    @Resource
    private SalaryService salarysService;

    /** 查询所有数据
     * @return 工资列表
     */
    @RequestMapping("/queryList")
    public ApiResult queryList(){
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,salarysService.queryList());
    }

    /**
     * 选择工资uid
     *
     * @param uid uid
     * @return {@link ApiResult}
     */
    @RequestMapping("/index")
    private ApiResult selectSalarysUid(String uid){
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE, Arrays.asList(salarysService.selectById(uid)));
    }
    /** 添加工资列
     *
     * @param salarys 工资
     * @return salarys
     */
    @RequestMapping("/add")
    public ApiResult addSalarys(Salarys salarys){

        return salarysService.addSalarys(salarys) ? new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) : new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);
    }

    /** 删除工资列
     *
     * @param uid uid
     * @return 结果
     */
    @RequestMapping("/delete")
    private ApiResult deleteSalarys(String uid){
        boolean ref = salarysService.deleteSalarys(uid);
        return ref ? new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) : new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);
    }

    /** 列表分页
     * @data 2021/12/14
     * @return 结果
     */
    @RequestMapping("/pages")
    private PagesResult selectPages(@RequestParam("page") int page, @RequestParam("limit") int limit)
    {
        IPage<Salarys> staffIPage = salarysService.selectPages(new Pages<>(page,limit));
        return new PagesResult(0,staffIPage.getRecords(),(int)staffIPage.getTotal(),staffIPage.getSize());
    }

    /** 查询一个员工的基本工资
     * @param uid 员工
     * @return 基本工资数据
     */
    @RequestMapping("/basic")
    private ApiResult selectBasic(String uid){
        BigDecimal bigDecimal = salarysService.selectBasic(uid);
       return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,bigDecimal);
    }

    /** 查询一个员工的工时
     *
     * @param uid 员工号
     * @return 工时
     */
    @RequestMapping("/work_duration")
    private ApiResult selectWorkDuration(String uid){
        Integer workDuration = salarysService.selectWorkDuration(uid);
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,workDuration);
    }


    /** 查询一个员工的水电费
     *
     * @param uid 员工号
     * @return 水电费
     */
    @RequestMapping("/sundry")
    private ApiResult selectSundry(String uid){
        BigDecimal sundryBigDecimal = salarysService.selectSundry(uid);
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,sundryBigDecimal);
    }


    /** 查询一个员工的全勤奖
     *
     * @param uid uid
     * @return 全勤奖
     */
    @RequestMapping("/fillTime")
    private ApiResult selectFillTime(String uid){
        BigDecimal fill_time = salarysService.selectFillTime(uid);
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,fill_time);
    }


    /** 查询一盒员工的请假次数
     *
     * @param uid uid
     * @return 请假次数
     */
    @RequestMapping("/leave")
    private ApiResult selectLeave(String uid){
        Integer leaveNumber = salarysService.selectLeave(uid);
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,leaveNumber);
    }


    /** 查询应发工资
     *
     * @param uid uid
     * @return 应发工资
     */
    @RequestMapping("/payble")
    private ApiResult selectPayble(String uid){
        BigDecimal payble = salarysService.selectPayble(uid);
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,payble);
    }


    /** 查询实发工资
     *
     * @param uid uid
     * @return 应发工资
     */
    @RequestMapping("/number")
    private ApiResult selectNumber(String uid){
        BigDecimal number = salarysService.selectNumber(uid);
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,number);
    }

    /** 乐观锁修改
     *
     * @param salarys 工资
     * @return 结果
     */
    @RequestMapping("/update")
    private ApiResult updateSalarys(Salarys salarys){
        return salarysService.updateSalarys(salarys)? new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) : new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);
    }

}
